import {
  q as c,
  p as M,
  ap as R,
  X as m,
  f as k,
  H as N,
  av as h,
  aw as O,
  k as u,
  m as z,
  l as D,
  as as t,
  at as d,
  au as F
} from "./index-b50e6ef9.js";
import { a as j, c as A, d as v } from "./banner-7c90b86e.js";
function q(y) {
  const g = c([]),
    s = c(!0),
    l = c({});
  M(), c(!1);
  const _ = R("reload"),
    p = m({
      pageSize: 10,
      currentPage: 1,
      pageSizes: [10, 20, 30],
      total: 0,
      align: "right",
      background: !0,
      small: !1
    }),
    x = m({
      text: "正在加载第一页...",
      viewBox: "-10, -10, 50, 50",
      spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    }),
    B = [
      {
        type: "selection",
        width: 55,
        align: "left",
        hide: ({ checkList: e }) => !e.includes("勾选列")
      },
      {
        label: "序号",
        type: "index",
        width: 70,
        hide: ({ checkList: e }) => !e.includes("序号列")
      },
      { label: "ID", prop: "banner_id", minWidth: 100 },
      { label: "banner名称", prop: "banner_name", minWidth: 120 },
      {
        label: "图片",
        prop: "banner_img",
        minWidth: 100,
        cellRenderer: e =>
          u("div", null, [
            " ",
            u(
              "img",
              {
                src: e.row.banner_img,
                style: "width: 100%; height: 100%;",
                alt: ""
              },
              null
            )
          ])
      },
      {
        label: "分类",
        prop: "banner_type",
        minWidth: 150,
        cellRenderer: () => u("span", null, [z("首页")])
      },
      { label: "排序", prop: "banner_order", minWidth: 150 },
      {
        label: "状态",
        minWidth: 130,
        cellRenderer: e => {
          var n;
          return u(
            D("el-switch"),
            {
              loading: (n = l.value[e.index]) == null ? void 0 : n.loading,
              modelValue: e.row.banner_status,
              "onUpdate:modelValue": r => (e.row.banner_status = r),
              "active-value": 1,
              "inactive-value": 2,
              "active-text": "已启用",
              "inactive-text": "已禁用",
              "on-color": "#ffff",
              "inline-prompt": !0,
              onChange: () => U(e)
            },
            null
          );
        }
      },
      { label: "创建时间", minWidth: 180, prop: "create_time" },
      { label: "操作", fixed: "right", width: 200, slot: "operation" }
    ],
    S = k(() => [
      "!h-[20px]",
      "reset-margin",
      "!text-gray-500",
      "dark:!text-white",
      "dark:hover:!text-primary"
    ]);
  async function w(e) {
    const n = { banner_id: e.banner_id },
      r = JSON.stringify(n),
      a = { value: t.enc.Base64.stringify(t.enc.Utf8.parse(r)) },
      i = await j(a);
    i.code == 200
      ? (d("删除成功", { type: "success" }), _())
      : d(i.msg, { type: "error" });
  }
  function C() {}
  function I(e) {}
  function J(e) {}
  function W(e) {}
  function T(e) {
    (x.text = `正在加载第${e}页...`),
      (s.value = !0),
      h(600).then(() => {
        s.value = !1;
      });
  }
  function U({ row: e, index: n }) {
    F.confirm(
      `确认要<strong>${
        e.banner_status === 1 ? "启用" : "停用"
      }</strong><strong style='color:var(--el-color-primary)'>${
        e.banner_name
      }</strong>轮播图吗?`,
      "系统提示",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        dangerouslyUseHTMLString: !0,
        draggable: !0
      }
    )
      .then(() => {
        l.value[n] = Object.assign({}, l.value[n], { loading: !0 });
        const r = {
            banner_id: e.banner_id,
            banner_status: e.banner_status,
            banner_name: e.banner_name,
            banner_img: e.banner_img,
            banner_order: e.banner_order,
            banner_type: e.banner_type
          },
          o = JSON.stringify(r),
          i = { value: t.enc.Base64.stringify(t.enc.Utf8.parse(o)) };
        A(i),
          setTimeout(() => {
            (l.value[n] = Object.assign({}, l.value[n], { loading: !1 })),
              d("已成功修改角色状态", { type: "success" });
          }, 300);
      })
      .catch(() => {
        e.banner_status === 1 ? (e.banner_status = 2) : (e.banner_status = 1);
      });
  }
  async function b(e, n) {
    s.value = !0;
    const o = JSON.stringify({ banner_id: e, banner_status: n }),
      i = { value: t.enc.Base64.stringify(t.enc.Utf8.parse(o)) },
      { data: f } = await v(i);
    (g.value = f.data),
      (p.total = f.total),
      setTimeout(() => {
        s.value = !1;
      }, 500);
  }
  async function V() {
    const n = JSON.stringify({ page: 1, pagesize: 20 }),
      o = { value: t.enc.Base64.stringify(t.enc.Utf8.parse(n)) },
      a = await v(o);
    a.code === 200
      ? ((g.value = a.data.data),
        (p.total = a.data.total),
        setTimeout(() => {
          s.value = !1;
        }, 500))
      : d(a.msg, { type: "error" });
  }
  const L = e => {
    e && (e.resetFields(), b());
  };
  return (
    N(() => {
      h().then(() => {
        const { setWatermark: e } = O(y.value.getTableDoms().tableWrapper);
        e("后台项目", {
          font: "16px Microsoft YaHei",
          globalAlpha: 0.8,
          forever: !0,
          width: 252,
          height: 80
        });
      }),
        V();
    }),
    {
      loading: s,
      columns: B,
      dataList: g,
      pagination: p,
      buttonClass: S,
      onSearch: b,
      resetForm: L,
      handleaddUser: C,
      handleDelete: w,
      handleSizeChange: I,
      handleCurrentChange: J,
      handleSelectionChange: W,
      onCurrentChange: T
    }
  );
}
export { q as useRole };
